package tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import lib.Command;
import lib.CommandParser;

import org.junit.Test;


/**
 * Unittests for {@link CommandParser}
 * 
 * @author abhip
 * 
 */
public class CommandParserTests {

    @Test
    public void ParseCommand_IgnoresExtraWhiteSpaces() {
        // Arrange:
        String testCommandName = "Update";
        String testCommandArg1 = "Abhishek";
        String testCommandArg2 = "Hello!";
        String testCommand = testCommandName + "        " + testCommandArg1
                + "       " + testCommandArg2;

        // Act:
        Command command = CommandParser.ParseCommand(testCommand);

        // Assert:
        assertNotNull("Command returned should not be null", command);
        assertEquals("CommandName should be " + testCommandName,
                testCommandName, command.CommandName());
        assertNotNull("Command arguments should not be null",
                command.CommandArgs());
        assertEquals("Command should have one argument", 2,
                command.CommandArgs().length);
        assertEquals("Command argument1 should be " + testCommandArg1,
                testCommandArg1, command.CommandArgs()[0]);
        assertEquals("Command argument2 should be " + testCommandArg2,
                testCommandArg2, command.CommandArgs()[1]);
    }

    @Test
    public void ParseCommand_ReturnsCommand() {
        // Arrange:
        String testCommandName = "CreateUser";
        String testCommandArg = "Abhishek";
        String testCommand = testCommandName + " " + testCommandArg;

        // Act:
        Command command = CommandParser.ParseCommand(testCommand);

        // Assert:
        assertNotNull("Command returned should not be null", command);
        assertEquals("CommandName should be " + testCommandName,
                testCommandName, command.CommandName());
        assertNotNull("Command arguments should not be null",
                command.CommandArgs());
        assertEquals("Command should have one argument", 1,
                command.CommandArgs().length);
        assertEquals("Command argument should be " + testCommandArg,
                testCommandArg, command.CommandArgs()[0]);
    }
}
